package com.aaa.controller;

import com.aaa.pojos.PackBean;
import com.aaa.pojos.Result;
import com.aaa.pojos.Student;
import com.aaa.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {

    @Resource
    private StudentService studentService;

    @GetMapping
    public Result query(
            String name,
                           Integer degree,
                           Integer clazzId,
          @RequestParam(defaultValue = "1") int page,
          @RequestParam(defaultValue = "10") int pageSize
    ){
        log.info("查询列表传递参数"+"name"+name+"degree"+degree+"clazzId"+clazzId);
        PackBean<Student> students=studentService.query(name,degree,clazzId,page,pageSize);
        log.info("返回students"+students);
        return Result.success(students);
    }

    @PostMapping
    public Result insertStudent(@RequestBody Student student){
        studentService.insertStudent(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result queryId(@PathVariable("id") Integer id){
        Student student = studentService.queryId(id);
        return Result.success(student);
    }

    @PutMapping
    public Result updateStudent(@RequestBody Student student){
    studentService.updateStudent(student);
    return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result deleteStudent(@PathVariable("ids") List<Integer> ids){
//        log.info("ids值"+ids);
        studentService.deleteStudent(ids);
        return Result.success();
    }

    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable("id")Integer id,@PathVariable("score") Integer score){
//        log.info("学生id"+id+"扣的分数"+score);
       studentService.violation(id,score);
        return Result.success();
    }
}
